package com.xuelang.pipeline.client.application;

import com.xuelang.pipeline.client.application.dto.ComponentDTO;
import com.xuelang.pipeline.client.application.dto.ComponentQuery;
import com.xuelang.pipeline.client.application.dto.ComponentTaskQuery;
import com.xuelang.pipeline.client.common.constant.DictDTO;
import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * 组件服务API
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
public interface IComponentService {

    /**
     * 查询组件列表(有过滤条件，可以分页)
     *
     * @param dtoPageParam
     * @return
     */
    @PostMapping(value = "/pageList", produces = "application/json;charset=utf-8")
    ApiResult<PageRecord<ComponentDTO>> pageComponentList(@RequestBody @Valid PageParam<ComponentQuery> dtoPageParam);

    /**
     * 查询组件列表(有过滤条件)
     *
     * @param componentQuery
     * @return
     */
    @PostMapping(value = "/list", produces = "application/json;charset=utf-8")
    ApiResult<List<ComponentDTO>> conditionalComponentList(@RequestBody @Valid ComponentQuery componentQuery);

    /**
     * 根据关键字（组件名称）来查询组件数组
     * @param keyword
     * @return
     */
    @GetMapping(value = "/listComponentByKeyword", produces = "application/json;charset=utf-8")
    ApiResult<List<ComponentDTO>> listComponentByKeyword(@RequestParam("keyword") String keyword);

    /**
     * 新增组件
     *
     * @param componentDTO
     * @return
     */
    @PostMapping(value = "", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> addComponent(@RequestBody @Valid ComponentDTO componentDTO);

    /**
     * 更新组件
     *
     * @param componentDTO
     * @return
     */
    @PutMapping(value = "", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> updateComponent(@RequestBody @Valid ComponentDTO componentDTO);

    /**
     * 删除组件
     *
     * @param componentLabel
     * @return
     */
    @DeleteMapping(value = "/{componentLabel}", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> deleteComponent(@PathVariable("componentLabel") String componentLabel);

    /**
     * 根据label查询组件
     *
     * @param componentLabel
     * @return
     */
    @GetMapping(value = "/label/{componentLabel}", produces = "application/json;charset=utf-8")
    ApiResult<ComponentDTO> queryComponent(@PathVariable("componentLabel") String componentLabel);


    /**
     *  根据组件id查询仓库信息字典
     * @param query
     * @return
     */
    @PostMapping(value = "/repo/dict", produces = "application/json;charset=utf-8")
    ApiResult<List<DictDTO>> queryRepoDictByComponentId(@RequestBody @Valid ComponentTaskQuery query);


    /**
     * 根据组件id查询token信息字典
     * @param query
     * @return
     */
    @PostMapping(value = "/token/dict", produces = "application/json;charset=utf-8")
    ApiResult<List<DictDTO>> queryTokenDictByComponentId(@RequestBody @Valid ComponentTaskQuery query);

    /**
     * 根据id查询组件
     * @param componentLabel
     * @return
     */
    @GetMapping(value = "/{id}", produces = "application/json;charset=utf-8")
    ApiResult<ComponentDTO> queryByid(@PathVariable("id") String componentLabel);
}
